<?php
namespace Admin\Controller;
use Think\Controller;
class LouyuController extends CommonController {
    /*楼宇概况*/
    public function lygk(){

        $this->display();
    }

    /*组织设置*/
    public function zzsz(){
        $page = A('Admin/Page');
        $table  = 'louyu as a';
        $field  = 'a.*,b.name';
        $where  = "hd_user as b  on a.operator=b.id  and a.deletes = 1 and a.category = 1";
        $order  = 'id';
        $sum    = 20;
        $join   = 1;
        $info   = $page ->page($table, $field, $where, $order, $sum, $join);
        $this->assign('list',$info[0]);// 赋值数据集
        $this->assign('page',$info[1]);// 赋值分页输出
        $this->display();
    }
    /*组织设置修改*/
    public function zz_edit(){
        $id = I('get.sid');
        $zuzhi=M('louyu');
        $rs = $zuzhi->where("id = $id and deletes = 1 and category = 1")->find();
        $this->assign('rs',$rs);
        if(IS_POST){
            $data['title']= $_POST['title'];
            $data['content']= $_POST['content'];
            $data['operator'] = $_SESSION['userid'];
            $data['time'] = time();
            $data['category'] = 1;
            $result = $zuzhi->where("id=$id and deletes = 1 and category = 1")->save($data);
            if(!$result){
                $this->error('文章修改失败');
            }else{
                $this->success('文章修改成功',U('Louyu/zzsz'));
                exit;
            }
        }
        $this->display();
    }

    /*两新组织*/
    public function lxzz(){


        $this->display();
    }
    /*队伍建设*/
    public function dwjs(){
        $page = A('Admin/Page');
        $table  = 'louyu as a';
        $field  = 'a.*,b.name';
        $where  = "hd_user as b  on a.operator=b.id  and a.deletes = 1 and a.category = 2";
        $order  = 'id';
        $sum    = 20;
        $join   = 1;
        $info   = $page ->page($table, $field, $where, $order, $sum, $join);
        $this->assign('list',$info[0]);// 赋值数据集
        $this->assign('page',$info[1]);// 赋值分页输出
        $this->display();
    }
    /*队伍建设-文章增加*/
    public function dwjs_add(){
        if(IS_POST){
            $data['title']= $_POST['title'];
            $data['content']= $_POST['content'];
            $data['operator'] = $_SESSION['userid'];
            $data['time'] = time();
            $data['category'] = 2;
            $result = M('louyu')->add($data);
            if(!$result){
                $this->error('文章发布失败');
            }else{
                $this->success('文章发布成功',U('Louyu/dwjs'));
                exit;
            }
        }
        $this->display();
    }
    /*队伍建设-文章修改*/
    public function dwjs_edit(){
        $id = I('get.sid');
        $zuzhi=M('louyu');
        $rs = $zuzhi->where("id = $id and deletes = 1 and category = 2")->find();
        $this->assign('rs',$rs);
        if(IS_POST){
            $data['title']= $_POST['title'];
            $data['content']= $_POST['content'];
            $data['operator'] = $_SESSION['userid'];
            $data['time'] = time();
            $data['category'] = 2;
            $result = $zuzhi->where("id=$id and deletes = 1 and category = 2")->save($data);
            if(!$result){
                $this->error('文章修改失败');
            }else{
                $this->success('文章修改成功',U('Louyu/dwjs'));
                exit;
            }
        }
        $this->display();
    }
    /*队伍建设删除*/
    public function del(){
        $id = I('post.id');
        $louyu=M('louyu');
        $data['deletes'] = 2;
        $rs=$louyu->where("id = $id")->save($data);
        if($rs){
            $this->ajaxReturn("ok");
        } else {
            $this->ajaxReturn("sss");
        }

    }

    /*星级楼宇*/
    public function xjly(){
        $page = A('Admin/Page');
        $table  = 'louyu as a';
        $field  = 'a.*,b.name';
        $where  = "hd_user as b  on a.operator=b.id  and a.deletes = 1 and a.category = 3";
        $order  = 'id';
        $sum    = 20;
        $join   = 1;
        $info   = $page ->page($table, $field, $where, $order, $sum, $join);
        $this->assign('list',$info[0]);// 赋值数据集
        $this->assign('page',$info[1]);// 赋值分页输出
        $this->display();
    }
    /*星级楼宇—修改*/
    public function xjly_edit(){
        $id = I('get.sid');
        $zuzhi=M('louyu');
        $rs = $zuzhi->where("id = $id and deletes = 1 and category = 3")->find();
        $this->assign('rs',$rs);
        if(IS_POST){
            $data['title']= $_POST['title'];
            $data['content']= $_POST['content'];
            $data['operator'] = $_SESSION['userid'];
            $data['time'] = time();
            $data['category'] = 3;
            $result = $zuzhi->where("id=$id and deletes = 1 and category = 3")->save($data);
            if(!$result){
                $this->error('文章修改失败');
            }else{
                $this->success('文章修改成功',U('Louyu/xjly'));
                exit;
            }
        }
        $this->display();
    }
}